package com.hanlink.dsp.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;

import com.qztech.sdk.R;

/**
 * Copyright (C), 深圳市东乘电子科技有限公司
 * Carate By YangZhong
 */
public class ConfirmInputDialog extends Dialog implements View.OnClickListener {
    private TextView mTvOk, mTvCancel;
    private EditText mEt;
    public ConfirmInputDialog(@NonNull Context context) {
        this(context, R.style.dialog);

    }

    public ConfirmInputDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);

        setContentView(R.layout.confirm_input_dialog);
        mTvOk = findViewById(R.id.tvOk);
        mTvCancel = findViewById(R.id.tvCancel);
        mEt = (EditText) findViewById(R.id.etPassword);
        mTvOk.setOnClickListener(this);
        mTvCancel.setOnClickListener(this);
        setCanceledOnTouchOutside(true);
    }


    public EditText getEditText() {
        return mEt;
    }

    private View.OnClickListener mCancelListener;
    public void setOnCancelListener(View.OnClickListener l){
        mCancelListener = l;
    }
    private OnConfigInputDialogOkListener mOkListener;
    public void setOnOkListener(OnConfigInputDialogOkListener l){
        mOkListener = l;
    }


    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.tvOk){
            if (mOkListener != null){
                mOkListener.onOkClick(this, mEt.getText().toString());
            }
        }else if (v.getId() == R.id.tvCancel){
            dismiss();
            if (mCancelListener != null)
                mCancelListener.onClick(v);

        }

    }

    public interface OnConfigInputDialogOkListener{
        void onOkClick(Dialog dialog, String text);
    }
}
